package ufpr.mestrado.ais.base.operator.comparator;

import java.util.Comparator;

import ufpr.mestrado.ais.base.SolutionMNO;

public class ObjectiveComparatorMNO implements Comparator {
	
	
	
	/**F
	 * Stores the index of the objective to compare
	 */
	private int nObj;

	/**
	 * Constructor.
	 * 
	 * @param nObj
	 *            The index of the objective to compare
	 */
	public ObjectiveComparatorMNO(int nObj) {
		this.nObj = nObj;
	} // ObjectiveComparator

	/**
	 * Compares two solutions.
	 * 
	 * @param o1
	 *            Object representing the first <code>Solution</code>.
	 * @param o2
	 *            Object representing the second <code>Solution</code>.
	 * @return -1, or 0, or 1 if o1 is less than, equal, or greater than o2,
	 *         respectively.
	 */
	public int compare(Object o1, Object o2) {
		if (o1 == null)
			return 1;
		else if (o2 == null)
			return -1;

		double objetive1 = ((SolutionMNO) o1).getObjectiveS(this.nObj);
		double objetive2 = ((SolutionMNO) o2).getObjectiveS(this.nObj);
		if (objetive1 < objetive2) {
			return -1;
		} else if (objetive1 > objetive2) {
			return 1;
		} else {
			return 0;
		}
	} // compare
}
